const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');
const ModelTask = require('./ModelTask.js');

const Alarm = sequelize.define('Alarm', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  taskId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: ModelTask,
      key: 'id',
    }
  },
  description: {
    type: DataTypes.TEXT,
  },
}, {
  tableName: 'alarms',
  timestamps: true,
});

Alarm.belongsTo(ModelTask, { foreignKey: 'taskId' });

module.exports = Alarm;